package org.hawk.gwt.ppc.reflect.emul.java.lang.reflect;

import java.lang.reflect.Modifier;
/**
 * Provides common superclass for all reflection types that have access modifiers.
 * 
 * @author alex.bereznevatiy@gmail.com
 */
public abstract class AccessibleObject {
	private boolean accessible;

	protected void checkAccess() throws IllegalAccessException {
		if (accessible)
			return;
		if (!Modifier.isPublic(getModifiers())) {
			throw new IllegalAccessException(
					"Reflection access to non-public and non-acessible member");
		}
	}

	protected final void checkAccess(Object accessor) {
		if (accessor == null || !accessor.getClass().getName().equals("org.hawk.gwt.ppc.reflect.lang.ClassDelegate$Accessor")) {
			throw new IllegalAccessError("This call is not permitted");
		}
	}

	protected final void thereIsNoGenericSupport() {
		throw new UnsupportedOperationException("Generics are turned off. " +
				"Please refer to the preprocessor command line options to find out how to turn on generic support.");
	}
	
	public abstract int getModifiers();

	public boolean isAccessible() {
		return accessible;
	}

	public void setAccessible(boolean accessible) {
		this.accessible = accessible;
	}
}
